/*
 * Copyright 2011 Subhabrata Ghosh <subho.ghosh at langene.net>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */



package net.langene.nlp;

//~--- non-JDK imports --------------------------------------------------------

import net.langene.common.ProgramUtils;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.PosixParser;

//~--- JDK imports ------------------------------------------------------------

import java.io.File;


/**
 * Hello world!
 *
 */
public class App {
	/**
	 * Run the application.
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
        Options	options = new Options();
        Option	optconf = OptionBuilder.withArgName("conf").withLongOpt(
                             "config").hasArg().isRequired(true).withDescription(
                             "Application configuraiton file.").create("config");
        Option	optinput = OptionBuilder.withArgName("file").withLongOpt(
                              "input").hasArg().isRequired(true).withDescription(
                              "Text file containing input text.").create("input");

        options.addOption(optconf);
        options.addOption(optinput);

        try {
            CommandLineParser	parser     = new PosixParser();
            CommandLine		cmd        = parser.parse(options, args);
            String		configfile = null;
            String		inputfile  = null;

            if (cmd.hasOption("config")) {
                configfile = cmd.getOptionValue("config");
            } else {
                throw new Exception("Missing command line parameter -config.");
            }

            if (cmd.hasOption("input")) {
                inputfile = cmd.getOptionValue("input");

                File	fi = new File(inputfile);

                if (!fi.exists()) {
                    throw new Exception("Invalid input file. File [" + inputfile + "] not found.");
                }
            } else {
                throw new Exception("Missing command line parameter -input.");
            }

            try {
                Context.create(configfile);
            } catch (Exception nex) {
                nex.printStackTrace();
            }
        } catch (Exception ex) {
            ProgramUtils.usage(App.class.getCanonicalName(), ex.getLocalizedMessage(), options);
        }
    }
}


//~ Formatted by Jindent --- http://www.jindent.com
